package com.lkx;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.lkx.model.PhoneModel;
import com.lkx.util.ExcelUtil;

@Controller
public class TestController {
	
	@RequestMapping("/")
	public String ss1(){
		return "index";
	}
	
	@RequestMapping("/test")
	@ResponseBody
	public List<PhoneModel> testImport(MultipartFile file) throws IOException, Exception{

		String keyValue ="手机名称:phoneName,颜色:color,售价:price,时间:sj"; 
		List<PhoneModel> list = ExcelUtil.readXls(file.getBytes(), ExcelUtil.getMap(keyValue), "com.lkx.model.PhoneModel");
		return list;
	}

	@RequestMapping("/export")
	public void testExport(HttpServletResponse response) throws Exception{
		 
		List<PhoneModel> list = new ArrayList<PhoneModel>();
		for(int i=0;i<100;i++){
			PhoneModel model = new PhoneModel();
			model.setColor("金色"+i);
			model.setPhoneName("苹果"+i+"S");
			model.setPrice(i);
			list.add(model);
		}
		String keyValue ="手机名称:phoneName,颜色:color,售价:price,时间:sj"; 
		ExcelUtil.exportExcelOutputStream(response,keyValue,list,"com.lkx.model.PhoneModel","李凯旋测试Excel导出"); 
	}
	
	@RequestMapping("/json")
	@ResponseBody
	public BizResult<PhoneModel> ss(){
		
		List<PhoneModel> list = new ArrayList<PhoneModel>();
		
		
		PhoneModel model = new PhoneModel();
		model.setColor("土豪金");
		model.setPhoneName("ipone X");
		model.setSj(new Date());
		
		list.add(model);
		
		BizResult<PhoneModel> result = new BizResult<PhoneModel>();
		result.setCode("0");
		result.setData(model);
		result.setList(list);
		
		return result;
	}
	
}
